import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: sessionStorage.getItem('username')
  },
  getters: {
  },
  mutations: {
    updateUserInfo(state, payload) {
      state.user = payload
      // 修改用户信息时，将用户名存入sessionStorage
      window.sessionStorage.setItem('username', payload)
    },
    // 退出登录     $store.commit('logout')
    logout(state) {
      state.user = ''
      window.sessionStorage.removeItem('username')
    }
  },
  actions: {
  },
  modules: {
     login(store, payload){
      store.commit('updateUserInfo', 'username')
    }
  }
})
